#include "fileio.hpp"

BOOL WriteFile::write(CONST VOID *pvBuffer, DWORD nNumBytesToWrite)
{
	BOOL res = ::WriteFile(_hfile, pvBuffer, nNumBytesToWrite, &_pdwNumBytes, NULL);
	return res;
}

void WriteFile::open()
{
	init();
	_hfile = ::CreateFile(_fName, _dwDesiredAccess, _dwShareMode, NULL, _dwCreationDisposition, _dwFlagsAndAttributes, NULL);
}

void WriteFile::close()
{
	LARGE_INTEGER dis;
	dis.QuadPart = _pdwNumBytes;
	SetFilePointerEx(_hfile, dis, NULL, FILE_BEGIN);
	SetEndOfFile(_hfile);
	CloseHandle(_hfile);
}

FtpWriteFile::FtpWriteFile(const LPCWSTR fName)
	:WriteFile(fName)
{
}

void FtpWriteFile::init()
{
	_dwDesiredAccess = GENERIC_WRITE;
	_dwShareMode = 0;
	_dwCreationDisposition = CREATE_ALWAYS;
	_dwFlagsAndAttributes=FILE_FLAG_WRITE_THROUGH;
}
